package com.tkjt.pms.calc.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tkjt.pms.calc.CalcTraceUpdater;
import com.tkjt.pms.calc.common.IndexCalcParallel;
import com.tkjt.pms.calc.formula.utils.FormulaParamHelper;
import com.tkjt.pms.common.IndexParam;
import com.tkjt.pms.persist.dao.IndexCalcTraceDao;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class CalcTraceUpdaterImpl implements CalcTraceUpdater {

	@Autowired
	private IndexCalcTraceDao indexCalcTraceDao;

	@Override
	public void updateCalcTraceSuccess(IndexParam indexParam, IndexCalcParallel indexCalcParallel) {

		log.debug("indexCalcParallel={}", indexCalcParallel);
		
		indexCalcTraceDao.updateCalcTraceSuccess(indexParam, indexCalcParallel);

	}
	
	@Override
	public void updateCalcTraceException(IndexParam indexParam, IndexCalcParallel indexCalcParallel) {

		String currentWhichData = FormulaParamHelper.getFormulaCurrentWhichData(indexParam);
		String exception = FormulaParamHelper.getFormulaException(indexParam, currentWhichData);
		
		log.debug("exception=\r\n{}\r\n", exception);

		indexCalcTraceDao.updateCalcTraceException(indexParam, indexCalcParallel, exception);

	}

	@Override
	public void updateException(IndexParam indexParam, IndexCalcParallel indexCalcParallel, String exception) {

		log.debug("indexCalcParallel=\r\n{}\r\n", indexCalcParallel);
		log.debug("exception=\r\n{}\r\n", exception);

		indexCalcTraceDao.updateCalcTraceException(indexParam, indexCalcParallel, exception);
	}

}
